﻿namespace RL
{
    using System;
    using System.Web.UI.HtmlControls;

    public class AspNetAjax
    {
        public static string AddBeginRequest(string methodName)
        {
            return ("Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(" + methodName + ");");
        }

        public static string AddEndRequest(string methodName)
        {
            return ("Sys.WebForms.PageRequestManager.getInstance().add_endRequest(" + methodName + ");");
        }

        public static string AjaxMessageHandlingStart(HtmlInputHidden control, string splitter)
        {
            return ("\r\nvar dataItems = args.get_dataItems();\r\nvar returnedMessage = dataItems['" + control.ClientID + "'];\r\n\r\nif (returnedMessage != \"\" && returnedMessage != undefined)\r\n{ \r\n\r\narr = returnedMessage.split(\"" + splitter + "\");\r\nvar situation = arr[0];\r\nswitch(situation)\r\n{\r\ncase \"right\":\r\n\r\nbreak;\r\n\r\ncase \"top\":\r\nshowStatusMessage(arr[0],arr[1],arr[2],arr[3],arr[4],arr[5],arr[6],arr[7],arr[8],arr[9],arr[10]);\r\nbreak;\r\n\r\ncase \"bottom\":\r\n\r\nbreak;\r\n\r\ncase \"left\":\r\n\r\nbreak;\r\n\r\ncase \"topright\":\r\n\r\nbreak;\r\n\r\ncase \"bottomright\":\r\n\r\nbreak;\r\n\r\ncase \"topleft\":\r\n\r\nbreak;\r\n\r\ncase \"bottomleft\":\r\n\r\nbreak;\r\n}\r\n                   \r\n}\r\n\r\n");
        }

        public static string FunctionStub(string name, string code)
        {
            return RL.AjaxPlaceHolder.Function(name, code, new string[] { "sender", "args" }).ToString();
        }
    }
}

